package the_tenth_chapter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Scanner;

public class OutputStreamTest {

	public static void main(String[] args) {
		String s = System.getProperty("file.separator");
		String path = "C:/Users/Administrator/Desktop/1.txt";
		path = path.replace("/", s);
		File file = new File(path);

		Scanner input = null;
		OutputStream os = null;

		input = new Scanner(System.in);
		byte[] b = null;
		String data = null;
		try {
			os = new FileOutputStream(file);
			while (input.hasNext()) {
				data = input.nextLine();
				if (data != null) {
					b = data.getBytes();
				} else {
					b = "".getBytes();
				}
				os.write(b, 0, b.length);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				input.close();
				os.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}
}
